<%@ page contentType="text/html;charset=UTF-8" language="java" pageEncoding="UTF-8" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="/WEB-INF/mytaglib.tld" prefix="mytag" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<fmt:setBundle basename="ua.races.raceBundle"/>

<html>
<head>
    <title>Adding new race</title>
</head>
<body>
<c:set var="logoutText"><fmt:message key="logout"/></c:set>
<mytag:logout text="${logoutText}"/>

<jsp:useBean id="stadiums" type="java.util.Set" scope="request"/>
<jsp:useBean id="horses" type="java.util.List" scope="request"/>
<jsp:useBean id="numberOfHorses" type="java.lang.Integer" scope="request"/>

<c:set var="dateText"><fmt:message key="races.date"/></c:set>
<c:set var="submitText"><fmt:message key="admin.addRace.submit"/></c:set>
<c:set var="timeText"><fmt:message key="races.startTime"/></c:set>
<c:set var="horsesText"><fmt:message key="races.horses"/></c:set>
<c:set var="stadiumText"><fmt:message key="races.stadium"/></c:set>
<c:set var="newStadiumText"><fmt:message key="admin.addRace.new.stadium"/></c:set>
<c:set var="newHorseText"><fmt:message key="admin.addRace.new.horse"/></c:set>


<form action="postRace.do" method="GET">
    <table>
        <tr>
            <td>${dateText}</td>
            <td><input type="text" name="date"></td>
        </tr>
        <tr>
            <td>${stadiumText}</td>
            <td>
                <div style="text-align: center;">
                    <table>
                        <tr>
                            <td>
                                <select name="stadium">
                                    <c:forEach var="stadium" items="${stadiums}">
                                        <option>${stadium}</option>
                                    </c:forEach>
                                    <option>${newStadiumText}</option>
                                </select>
                            </td>
                            <td>
                                <input type="text" name="newStadium"/>
                            </td>
                        </tr>
                    </table>
                </div>
        </tr>
        <tr>
            <td>${timeText}</td>
            <td><input type="text" name="time"></td>
        </tr>
        <tr>
            <td>${horsesText}</td>
            <td>
                <div style="text-align: center;">
                    <table>
                        <c:forEach var="i" begin="1" end="${numberOfHorses}">
                            <tr>
                                <td>
                                    <select name="horse">
                                        <c:forEach var="horse" items="${horses}">
                                            <option>${horse.horseName}</option>
                                        </c:forEach>
                                        <option>${newHorseText}</option>
                                    </select>
                                </td>
                                <td><input type="text" name="horseName"></td>
                            </tr>
                        </c:forEach>
                    </table>
                </div>
            </td>
        </tr>
        <tr>
            <td></td>
            <td><input type="submit" value="${submitText}"></td>
        </tr>
    </table>
</form>

</body>
</html>